package employee;


import java.util.Scanner;

public class Oprea {
    static Employee emps[]=Init.emps;
    static Porson pors[]=Init.pors;
    //登录菜单
    public boolean denglu(){
        Scanner input = new Scanner(System.in);
        System.out.println("请输入用户名:");
        String name = input.next();
        System.out.println("请输入密码:");
        String password = input.next();
        boolean flag = false;
        for (int i = 0; i <pors.length ; i++) {
            if (pors[i].getPorName().equals(name)&&pors[i].getPassword().equals(password)){
                System.out.println("登陆成功");
                flag=true;
            }
        }
        return flag;
    }
    //主菜单
    public void twoCaiDan(){
        Init init = new Init();
        Scanner input = new Scanner(System.in);
        do {
            System.out.println("请输入你要选择的服务");
            System.out.println("1.查询所有员工信息");
            System.out.println("2.根据工号查询员工信息");
            System.out.println("3.添加员工");
            System.out.println("4.修改员工工资");
            System.out.println("5.删除员工");
            System.out.println("6.退出");
            System.out.println("请输入你要选择的服务:");
            int num = input.nextInt();
            switch (num){
                case 1:
                    //遍历员工
                    for (int i = 0; i <emps.length ; i++) {
                        if (emps[i]!=null){
                            System.out.println("工号\t姓名\t工资");
                            System.out.println(emps[i].getEmpNo()+"\t\t"+emps[i].getEmpName()+"\t\t"+emps[i].getEmpMoney());
                        }
                    }
                    break;
                case 2:
                    //查找员工
                    System.out.println("请输入工号:");
                    int num1 = input.nextInt();
                    for (int i = 0; i <emps.length ; i++) {
                        if (emps[i].getEmpNo()==(num1)){
                            System.out.println("找到了");
                            System.out.println(emps[i].getEmpNo()+"\t"+emps[i].getEmpName()+"\t"+emps[i].getEmpMoney());
                            break;
                        }else {
                            System.out.println("没有找到该工号的信息。");
                            System.out.println("请重新输入:");
                            num1 = input.nextInt();
                        }
                    }
                    break;
                case 3:
                    //添加员工
                    System.out.println("请输入你要添加的员工的工号:");
                    int num3 = input.nextInt();
                    System.out.println("请输入你要添加的员工的姓名:");
                    String name = input.next();
                    System.out.println("请输入你要添加的员工的工资:");
                    int money = input.nextInt();
                    for (int i = 0; i <emps.length ; i++) {
                        if (emps[i]==null){
                            Employee tianJia=new Employee(num3,name,money);
                            init.addEmp(tianJia);
                            System.out.println("添加成功");
                            break;
                        }
                    }
                    break;
                case 4:
                    //修改员工工资
                    System.out.println("请输入你要修改员工工资的工号:");
                    int num4=input.nextInt();
                    System.out.println("请输入你要更改的工资");
                    int money2=input.nextInt();
                    for (int i = 0; i <emps.length ; i++) {
                        if (emps[i].getEmpNo()==num4){
                            emps[i].setEmpMoney(money2);
                            System.out.println("修改成功");
                            break;
                        }else{
                            System.out.println("没有找到你要修改工资的人");
                            System.out.println("修改失败");
                            break;
                        }
                    }
                    break;
                case 5:
                    System.out.println("请输入你要删除的员工的工号");
                    int num2=input.nextInt();
                    for (int i = 0; i <emps.length ; i++) {
                        if (emps[i].getEmpNo()==num2){
                            emps[i]=null;
                            System.out.println("删除成功");
                            break;
                        }else {
                            System.out.println("没有找到你要删除的员工");
                            System.out.println("删除失败");
                        }
                    }
                    break;
                case 6 :
                    System.out.println("退出");
                    System.out.println("欢迎下次使用!");
                    return;
            }
            System.out.println("输入0返回");
            num = input.nextInt();
        }while (true);

    }
}
